<!DOCTYPE html>
<html lang="en" th:with="title='系统设置',active='setting'" xmlns:th="http://www.thymeleaf.org">
<header th:replace="admin/fragments/header::headerFragment(${title},${active})"></header>
<link rel="stylesheet" th:href="@{/admin/plugins/toggles/toggles.css}"/>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/fragments/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">系统设置</h4>
                    </div>
                    <div class="col-md-6">
                        <div class="panel panel-color panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title">全局设置</h3>
                            </div>
                            <div class="panel-body">
                                <form class="form-horizontal" id="global-form" role="form">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点名称</label>
                                        <div class="col-md-9">
                                            <input aria-required="true" class="form-control" name="site_title"
                                                   placeholder="站点名称"
                                                   required="required" th:value="${options.site_title}" type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">站点描述</label>
                                        <div class="col-md-9">
                                            <input aria-required="true" class="form-control" name="site_description"
                                                   placeholder="站点描述"
                                                   required="required" th:value="${options.site_description}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">ICP备案号</label>
                                        <div class="col-md-9">
                                            <input aria-required="true" class="form-control" name="site_record"
                                                   placeholder="ICP备案号"
                                                   required="required" th:value="${options.site_record}" type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">google网站验证码</label>
                                        <div class="col-md-9">
                                            <input aria-required="true" class="form-control"
                                                   name="google_site_verification" placeholder="google网站验证码"
                                                   required="required" th:value="${options.google_site_verification}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">百度网站验证码</label>
                                        <div class="col-md-9">
                                            <input aria-required="true" class="form-control"
                                                   name="baidu_site_verification" placeholder="百度网站验证码"
                                                   required="required" th:value="${options.baidu_site_verification}"
                                                   type="text"/>
                                        </div>
                                    </div>

                                    <!--<div class="form-group">-->
                                    <!--<label class="col-md-3 control-label">博客主题</label>-->
                                    <!--<div class="col-md-9">-->
                                    <!--<select name="site_theme" class="form-control">-->
                                    <!--<option value="default" th:selected="${options.site_theme=='default'}?true:false">默认主题</option>-->
                                    <!--</select>-->
                                    <!--</div>-->
                                    <!--</div>-->

                                    <input id="allow_install" name="allow_install" type="hidden"/>
                                    <div class="clearfix pull-right">
                                        <button class="btn btn-primary waves-effect waves-light" onclick="saveSetting()"
                                                type="button">
                                            保存设置
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-6">
                        <div class="panel panel-color panel-inverse">
                            <div class="panel-heading">
                                <h3 class="panel-title">个性化设置</h3>
                            </div>
                            <div class="panel-body">
                                <form class="form-horizontal" id="indivi-form" role="form">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">CSDN博客</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_csdn"
                                                   placeholder="CSDN博客，不输入则不显示"
                                                   th:value="${options.social_csdn}"
                                                   type="text"/>
                                        </div>

                                        <label class="col-md-3 control-label">简历</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_resume"
                                                   placeholder="简历地址，不输入则不显示"
                                                   th:value="${options.social_resume}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">简书</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_jianshu" placeholder="简书账号，不输入则不显示"
                                                   th:value="${options.social_jianshu}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">微博账号</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_weibo" placeholder="微博账号，不输入则不显示"
                                                   th:value="${options.social_weibo}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">知乎账号</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_zhihu" placeholder="知乎账号，不输入则不显示"
                                                   th:value="${options.social_zhihu}"
                                                   type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">Github账号</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_github"
                                                   placeholder="Github账号，不输入则不显示"
                                                   th:value="${options.social_github}" type="text"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">Twitter账号</label>
                                        <div class="col-md-9">
                                            <input class="form-control" name="social_twitter"
                                                   placeholder="Twitter账号，不输入则不显示"
                                                   th:value="${options.social_twitter}" type="text"/>
                                        </div>
                                    </div>
                                    <div class="clearfix pull-right">
                                        <button class="btn btn-inverse waves-effect waves-light"
                                                onclick="saveIndiviSetting()"
                                                type="button">
                                            保存设置
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix"></div>

                    <!--<div class="col-md-6">-->
                    <!--<div class="panel panel-color panel-success">-->
                    <!--<div class="panel-heading">-->
                    <!--<h3 class="panel-title">系统备份（备份文件包含附件和主题）</h3>-->
                    <!--</div>-->
                    <!--<div class="panel-body">-->
                    <!--<form id="backupForm" class="form-inline" role="form">-->
                    <!--&lt;!&ndash;<div class="form-group">-->
                    <!--<label class="sr-only">备份格式</label>-->
                    <!--<input name="url" class="form-control" placeholder="请输入备份文件格式，如yyyy-MM-dd" required="" aria-required="true" type="url">-->
                    <!--</div>&ndash;&gt;-->
                    <!--<div class="form-group col-md-6">-->
                    <!--<input id="backup_dir" style="width: 100%;" class="form-control" placeholder="请输入备份存放的磁盘路径" required="" aria-required="true" type="text"/>-->
                    <!--</div>-->

                    <!--<button type="button" class="btn btn-success waves-effect waves-light m-l-10" onclick="backup('attach');">备份文件</button>-->
                    <!--<button type="button" class="btn btn-danger waves-effect waves-light m-l-10" onclick="backup('db')">导出数据库SQL</button>-->
                    <!--</form>-->
                    <!--</div>-->
                    <!--</div>-->
                    <!--</div>-->

                </div>
                <div th:replace="admin/fragments/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/fragments/footer :: footer"></div>
<script src="//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js"></script>
<script type="text/javascript">
    /*<![CDATA[*/
    var tale = new $.tale();

    /**
     * 保存全局设置
     */
    function saveSetting() {
        var param = $('#global-form').serialize();
        tale.post({
            url: '/admin/setting',
            data: param,
            success: function (result) {
                if (result && result.code == 'success') {
                    tale.alertOk('设置保存成功');
                } else {
                    tale.alertError(result.msg || '设置保存失败');
                }
            }
        });
    }

    /**
     * 保存个性化设置
     */
    function saveIndiviSetting() {
        var param = $('#indivi-form').serialize();
        tale.post({
            url: '/admin/setting',
            data: param,
            success: function (result) {
                if (result && result.code == 'success') {
                    tale.alertOk('设置保存成功');
                } else {
                    tale.alertError(result.msg || '设置保存失败');
                }
            }
        });
    }

    /**
     * 设置是否允许重新安装
     */
    function allow_reinstall(obj) {
        var this_ = $(obj);
        var on = this_.find('.toggle-on.active').length;
        var off = this_.find('.toggle-off.active').length;
        if (on == 1) {
            $('#allow_install').val(0);
        }
        if (off == 1) {
            $('#allow_install').val(1);
        }
    }

    /**
     * 系统备份
     * @param type
     */
    function backup(type) {
        var param = {
            bk_type: type,
            bk_path: $('#backup_dir').val()
        };
        tale.post({
            url: '/admin/setting/backup',
            data: param,
            success: function (result) {
                if (result && result.code == 'success') {
                    if (result.payload && result.payload.attach_path) {
                        swal('备份成功', '您的附件备份在 <mark>' + result.payload.attach_path + '</mark><br/><br/>' +
                            '主题备份存储在 <mark>' + result.payload.theme_path + '</mark>', 'success');
                        $('#backup_dir').val('');
                    }
                    if (result.payload.sql_path) {
                        window.location.href = '/upload/' + result.payload.sql_path;
                    }
                } else {
                    tale.alertError(result.msg || '备份失败');
                }
            }
        });
    }

    $('.allow-1').toggles({
        on: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
    $('.allow-0').toggles({
        off: true,
        text: {
            on: '开启',
            off: '关闭'
        }
    });
    /*]]>*/
</script>
</body>
</html>